using System;
using System.Collections.Generic;
using NHibernate;
using Symbonix.NorSoNet.Communication;
using Symbonix.Library.Data.NHibernate;
using System.Collections;
using NHibernate.Criterion;

namespace Symbonix.NorSoNet.Communication.DAL.Repositories
{
	public partial class FriendDataRepository : BaseRepository<FriendData,Int32>
	{
        public bool IsFriend(int userId,int friendId)
        {

            ISQLQuery countQuery = NHibernateHelper.CurrentSession.CreateSQLQuery(@"select count(*) from [Friend] 
                where ([RequestingUserID] =:RequestingUserID AND [RequestedUserID] = :RequestedUserID) or ([RequestingUserID] =:RequestedUserID AND [RequestedUserID] = :RequestingUserID)");
            countQuery.SetString("RequestingUserID", userId.ToString());
            countQuery.SetString("RequestedUserID", friendId.ToString());

            int totalItems = (int)countQuery.UniqueResult();
            return (totalItems > 0);
        }

        public IList<FriendData> GetAllFriends(int userId)
        {
            ICriteria criteria = GetCriteria();
            criteria.Add(Expression.Eq("RequestingUserID", userId));
            //criteria.Add(Expression.Eq("RequestedUserID", userId));
            IList<FriendData> result = criteria.List<FriendData>();
            return result;
        }
	}
}
